//
//  ILCollectionReusableView.m
//  UIHomeWork14_礼物说分类攻略界面
//
//  Created by tusm on 16/8/3.
//  Copyright © 2016年 tusm. All rights reserved.
//

#import "ILCollectionReusableView.h"
#import "ILCollectionViewCell.h"
#define kCollectionViewImageLabelReuse @"imageLabelReuse"

@interface ILCollectionReusableView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *button;
@end
@implementation ILCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat width = CGRectGetWidth(frame);
        CGFloat height = CGRectGetHeight(frame) / 5;
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, width - 20, height / 2)];
        _textField.placeholder = @"快选一份七夕礼物,送给心爱的Ta吧";
        _textField.font = [UIFont systemFontOfSize:14];
        _textField.textAlignment = NSTextAlignmentCenter;
        _textField.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
        _label = [[UILabel alloc] initWithFrame:CGRectMake(10, height / 2, (width - 20) / 2, height / 2)];
        _label.text = @"栏目";
        _label.font = [UIFont systemFontOfSize:14];
        _label.textColor = [UIColor grayColor];
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(width - 100, height / 2, 100, height / 2);
        [_button setTitle:@"查看全部>" forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont systemFontOfSize:14];
        [_button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self addSubview:_textField];
        [self addSubview:_label];
        [self addSubview:_button];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(width * 4 / 5, (CGRectGetHeight(frame) - height - 40) / 3);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumInteritemSpacing = 10;
        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        layout.headerReferenceSize = CGSizeMake(0, 50);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, height, CGRectGetWidth(frame), CGRectGetHeight(frame) - height) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsHorizontalScrollIndicator = NO;
        [_collectionView registerClass:[ILCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewImageLabelReuse];
        [self addSubview:_collectionView];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 30;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ILCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewImageLabelReuse forIndexPath:indexPath];
    return cell;
}

@end
